package icu.zhhll.util.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author zh
 * @date 2023/8/14 17:19
 */
public class StreamUtils {
    /**
     * inputStream转byte
     *
     * @param inStream
     * @return
     * @throws IOException
     * @author zhanghe
     */
    public static byte[] readStreamToBytes(InputStream inStream) throws IOException {

        return FileUtils.readBytes(inStream);
    }

    /**
     * 读取请求流,默认编码格式为UTF-8
     *
     * @param in
     * @return
     * @author zhanghe
     */
    public static String readStream(InputStream in) throws IOException {
        return readStream(in, "UTF-8");
    }

    /**
     * 读取请求流
     *
     * @param in
     * @param encoding
     * @return
     * @author zhanghe
     */
    public static String readStream(InputStream in, String encoding) throws IOException {
        byte[] bytes = readStreamToBytes(in);
        return new String(bytes, encoding);
    }


}
